// 此函数执行会返回一个数组 数组里面包含两个用户信息
function createUserList() {
    return [
      {
        id: 1,
        avatar: "http://47.121.182.69/images/avatar1.jpg",
        username: "admin",
        password: "123456",
        nickname: "超级管理员",
        roles: [{ id: 1, name: "经理" }],
        buttons: ["cuser.detail"],
        routes: ["btn.queryUser", "btn.queryRole"],
        token: "1",
      },
      {
        id: 2,
        avatar: "http://47.121.182.69/images/avatar2.jpg",
        username: "system",
        password: "123456",
        nickname: "系统管理员",
        roles: [{ id: 2, name: "老板" }],
        buttons: ["cuser.detail", "cuser.user"],
        routes: ["btn.queryUser", "btn.queryRole"],
        token: "2",
      },
    ];
  }
  
  /**
   * 对外暴露一个数组 数组里面包含两个接口：
   * 1. 登录
   * 2. 获取用户信息
   */
  export default [
    {
      url: "/user/login",
      method: "post",
      response: ( body : {username: string; password: string;} ) => {
        const { username, password } = body;
        const checkUser = createUserList().find(
          (item) => item.username === username && item.password === password
        );
        if (!checkUser) {
          return { code: 201, data: "账号或密码不正确" };
        }
        return { code: 200, data: checkUser.token };
      },
    },
    {
      url: "/user/info",
      method: "get",
      response: (request: any) => {
        const token = request.headers.token;
        const checkUser = createUserList().find((item) => item.token === token);
        if (!checkUser) {
          return { code: 201, data: { message: "获取登录用户失败" } };
        }
        return { code: 200, data: checkUser };
      },
    },
  ];
  